/**
 * ipassbook 0.6.0
 * Copyright (C)2009 wateray and contributors
 * wateray@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.wateray.ipassbook.ui.action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JTable;

import com.wateray.ipassbook.commom.Constant.Type;
import com.wateray.ipassbook.domain.form.PassbookTradeForm;
import com.wateray.ipassbook.ui.StandardFrame;
import com.wateray.ipassbook.ui.dialog.TransferDialog;
import com.wateray.ipassbook.ui.model.TransferTableModel;
import com.wateray.ipassbook.util.ImageManager;
import com.wateray.ipassbook.util.LanguageLoader;

/**
 * @author wateray
 * @create 2009-5-27
 */
public class ModifyTransferAction extends AbstractAction {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	private Object data;

	public ModifyTransferAction(){
		super(LanguageLoader.getString("Modify"));
		putValue(SHORT_DESCRIPTION, LanguageLoader.getString("Modify_Transfer"));
		this.setEnabled(false);
	}
	
	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		PassbookTradeForm transferForm = null;
		if(data instanceof JTable){
		  JTable table = (JTable) data;
		if(table.getSelectedRow() != -1){
			int selectedIndex = table.convertRowIndexToModel(table.getSelectedRow());
			transferForm = (PassbookTradeForm) ((TransferTableModel)table.getModel()).getRowObject(selectedIndex);
		}
	}
		//init dialog.
		TransferDialog dialog = new TransferDialog(StandardFrame.getInstance(),LanguageLoader.getString("Modify_Transfer"),Type.MODIFY, transferForm);
		dialog.getFinishButton().setText(LanguageLoader.getString("Modify"));
		dialog.setVisible(true);
	}
	
	public Object getData(){
		return data;
	}
	
	public void setData(Object data){
		 this.data = data;
	}
}
